R = 6371

import math as Math

from datetime import datetime

fmt='%m/%d/%Y %I:%M:%S %p'

f = open('c:/CSV_20100418051520.csv', 'r')
f1 = open('/x.csv', 'w')
f1.write('#;lat;lon;date;dist;time;speed;av;v/t;show\n')
import re
p = re.compile('[^,]+,([^,]+),([^,]+),[^,]+,([^,]+),')

lat1=0
lon1=0
d1=datetime(2010,1,1)
i=0
v0=0
for line in f.readlines()[1:]:
	m = p.search(line)
	la=m.group(1)
	lo=m.group(2)
	lat2=Math.radians(float(la))
	lon2=Math.radians(float(lo))
	d2=datetime.strptime(m.group(3), fmt)
	
	d=Math.acos(Math.sin(lat1)*Math.sin(lat2) + Math.cos(lat1)*Math.cos(lat2) * Math.cos(lon2-lon1)) * 6371 * 1000	
	t=(d2-d1).seconds
	v=d/t
	i+=1
	f1.write(str(i)+';'+la+';'+lo+';'+str(d2.strftime(fmt))+';'+str(d)+';'+str(t)+';'+str(3.6*v)+';'+str((v-v0)/t)+';'+str((v)/t)+';true\n')
	lat1=lat2
	lon1=lon2
	d1=d2
	v0=v

f.close()
f1.close()